package com.hsh.vo.param;

import com.hsh.tools.StrUtils;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.experimental.Accessors;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.util.Date;

/**
 * 请假申请参数
 */
@Data
@Accessors(chain = true)
@ApiModel(description = "申请请假参数类")
public class LeaveRecordParam {

    @ApiModelProperty(value = "请假申请人", hidden = true)
    private String userId;

    @ApiModelProperty(value = "请假类型（1：事假 ...）leave_type表中对应", allowableValues = "1,2,3")
    @NotNull(message = "请假类型不能为空")
    private Integer typeId;

    @ApiModelProperty(value = "请假开始时间【13位时间戳】")
    @NotBlank(message = "请假开始时间不能为空")
    private String startTimeFrom;

    @ApiModelProperty(value = "请假结束时间【13位时间戳】")
    @NotBlank(message = "请假结束时间不能为空")
    private String endTimeTo;

    @ApiModelProperty(value = "请假开始时间【13位时间戳】", hidden = true)
    private Date startTime;

    @ApiModelProperty(value = "请假结束时间【13位时间戳】", hidden = true)
    private Date endTime;

    public void constructionStartEndTime() {
        long from = new Long(this.startTimeFrom);
        this.startTime = new Date(from);

        long to = new Long(this.endTimeTo);
        this.endTime = new Date(to);
    }

    @ApiModelProperty(value = "请假时长")
    @NotNull(message = "请请假时长不能为空")
    private Integer leaveDuration;

    @ApiModelProperty(value = "请假原因")
    @NotBlank(message = "请假原因不能为空")
    private String leaveReason;

    @ApiModelProperty(value = "请假状态（1：审批中 2：已同意 3：已驳回）", hidden = true)
    private Integer leaveStatus = 1;

    @ApiModelProperty(value = "请假申请时间（默认当前时间）", hidden = true)
    private Date applyTime = new Date();

    // default param 审批流
    @ApiModelProperty(value = "直属上级审批人")
    @NotBlank(message = "直属上级审批人不能为空")
    private String zssjApprover;

    @ApiModelProperty(value = "直属上级审批人下的抄送人")
    private String zssjCs;

    @ApiModelProperty(value = "直属上级审批人下的抄送人【附属抄送人，以英文逗号相隔】")
    private String zssjCsFs;


    @ApiModelProperty(value = "人事行政审批人")
    private String rlxzApprover;

    @ApiModelProperty(value = "人事行政审批人下的抄送人【最终抄送人】")
    @NotBlank(message = "最终抄送人不能为空")
    private String rlxzCs;

    @ApiModelProperty(value = "人事行政审批人下的抄送人【最终抄送人】【附属抄送人，以英文逗号相隔】")
    private String rlxzCsFs;


    // 【普通员工】请假申请
    public boolean checkNormal() {
        return (StrUtils.isNotEmpty(zssjApprover) && StrUtils.isNotEmpty(zssjCs) && StrUtils.isNotEmpty(rlxzApprover) && StrUtils.isNotEmpty(rlxzCs));
    }

    // 【人事部负责人】请假申请【直属上级、最终抄送人】
    public boolean checkRsLeader() {
        return (StrUtils.isNotEmpty(zssjApprover) && StrUtils.isNotEmpty(rlxzCs));
    }

    // 【人事部普通员工】请假申请【人事行政审批、最终抄送人】
    public boolean checkRsNormal() {
        return (StrUtils.isNotEmpty(rlxzApprover) && StrUtils.isNotEmpty(rlxzCs));
    }

    // 【部门负责人】请假申请【直属上级、人事行政审批、最终抄送人】
    public boolean checkDeptLeader() {
        return (StrUtils.isNotEmpty(zssjApprover) && StrUtils.isNotEmpty(rlxzApprover) && StrUtils.isNotEmpty(rlxzCs));
    }
}
